#include "Parser.h"
#include <QDebug>

Parser::Parser(QString text)
{
    this->parse(text);
}

void Parser::parse(QString text)
{
    columns.clear();

    text.replace("\n", "");
    text.replace(" ", "");

    QStringList rows = text.split("\\", QString::SkipEmptyParts);


    foreach (QString row, rows) {
        QStringList eachRow = row.split("&", QString::SkipEmptyParts);
        if (columns.isEmpty()) {
            columns.fill(QStringList(), eachRow.count());
        }
        for (int i = 0; i < eachRow.count(); i++) {
            columns[i].append(eachRow[i]);
        }
    }
}

QStringList Parser::getColumn(int index)
{
    if (index >= columns.count())
        return QStringList();

    return columns.at(index);
}


